package com.shop;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;

import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrUIHandler;
import in.srain.cube.views.ptr.indicator.PtrIndicator;

/**
 * Created by niugao on 7/16/2016.
 * 自定义刷新头，用于PtrClassicFrameLayout
 */
public class RefreashHeaderView extends FrameLayout implements PtrUIHandler {
    private TextView mHeaderTextView = null;
    private TextView mHeaderUpdateText = null;
    private ImageView mHeaderPullDownImageView = null;
    private ImageView mHeaderReleaseDownImageView = null;
    private ProgressBar mHeaderProgressBar = null;

    public RefreashHeaderView(Context context) {
        super(context);
        View v = LayoutInflater.from(this.getContext()).inflate(R.layout.refresh_list_header, this);
        mHeaderTextView = (TextView) v.findViewById(R.id.refresh_list_header_text);

        mHeaderPullDownImageView = (ImageView) v.findViewById(R.id.refresh_list_header_pull_down);
        mHeaderReleaseDownImageView = (ImageView) v.findViewById(R.id.refresh_list_header_release_up);
        mHeaderProgressBar = (ProgressBar) v.findViewById(R.id.refresh_list_header_progressbar);


    }

    @Override
    public void onUIReset(PtrFrameLayout frame) {
        mHeaderTextView.setText("下拉刷新");
        mHeaderProgressBar.setVisibility(View.INVISIBLE);
        mHeaderPullDownImageView.setVisibility(View.VISIBLE);
        mHeaderReleaseDownImageView.setVisibility(View.GONE);
    }

    @Override
    public void onUIRefreshPrepare(PtrFrameLayout frame) {
        mHeaderTextView.setText("松手刷新");//显示松手刷新
        mHeaderPullDownImageView.setVisibility(View.GONE);//隐藏"下拉刷新"
        mHeaderReleaseDownImageView.setVisibility(View.VISIBLE);//显示向上的箭头
    }

    @Override
    public void onUIRefreshBegin(PtrFrameLayout frame) {
        mHeaderTextView.setText("正在加载...");
        mHeaderProgressBar.setVisibility(View.VISIBLE);
        mHeaderPullDownImageView.setVisibility(View.GONE);
        mHeaderReleaseDownImageView.setVisibility(View.GONE);
    }

    @Override
    public void onUIRefreshComplete(PtrFrameLayout frame) {
        mHeaderTextView.setText("完成，收功");


    }

    @Override
    public void onUIPositionChange(PtrFrameLayout frame,
                                   boolean isUnderTouch,
                                   byte status,
                                   PtrIndicator ptrIndicator) {

    }
}
